﻿namespace Skymate.Mvc.Controllers.Dynamic.Scripting
{
    using System.Net.Http;
    using System.Net.Http.Headers;

    using Skymate.Mvc.Controllers.Dynamic.Formatters;
    using Skymate.Mvc.Controllers.Dynamic.Scripting.TypeScript;
    using Skymate.Mvc.WebApis;

    public class TypeScriptController : SkymateApiController
    {
        readonly TypeScriptDefinitionGenerator _typeScriptDefinitionGenerator;
        public TypeScriptController(TypeScriptDefinitionGenerator typeScriptDefinitionGenerator)
        {
            this._typeScriptDefinitionGenerator = typeScriptDefinitionGenerator;
        }
        public HttpResponseMessage Get()
        {
            var script = this._typeScriptDefinitionGenerator.GetScript();
            var response = this.Request.CreateResponse(System.Net.HttpStatusCode.OK, script, new PlainTextFormatter());
            response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/x-javascript");
            return response;
        }
    }
}
